<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">
      
        <div class="layui-form-item">
          <label class="layui-form-label required" style="margin-left: 100px;">选择优惠券</label>
          <div class="layui-input-block">
              <div class="layui-input-block" id="test" lay-filter="test"></div>
          </div>
      </div>
      <input type="hidden" id="chendid" name="chendid" value="{$xid}">
        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
          <button type="button"  class="layui-btn layui-btn-delete layui-btn-sm" id="dianji">确定</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>
<script>
    // document.
    layui.config({
      base: '../../static/plugs/layui_exts/'
    }).extend({
      selectPlus: 'selectPlus/selectPlus'
    }).use(['selectPlus', 'jquery'], function () {
      var $ = layui.$,
        selectPlus = layui.selectPlus;
      var datas = '';
      var bb='';
      $.ajax({
          type:"get",
          url:"{:url('manageuser.user/qwe')}",
          data:'',
          async:false,
          success:function(data){
            datas = data;
          }
      })
    //   for(var i in datas){
    //      bb += datas[i]['name'] + ",";
    //   }
    //   var ss = bb.split(",");
      // 多选
      var test = selectPlus.render({
            el: '#test',
            data: datas,
            valueName: "name",
            values: ['bootstrap', 'element'],
            valueSeparator: ","
     });
    //  console.log(test.getChecked());
     
        $('#dianji').click(function(){
            var obj = test.getChecked();
            qwe = obj.data;
            var ww = '';
            for(var i in qwe){
                ww += qwe[i]['id'] + ",";
            }
            var job = document.getElementById("chendid");
            var xid = job.value;
            $.ajax({
                  url: '{:url("admin/manageuser.user/edit")}',
                  type: 'post',
                  data: {
                      xuanzhong:ww,
                      xid:xid
                  },
                  dataType: 'json',
                  success: function(data) {
                    if(data.code == 1){
                        layer.msg(data.msg,{icon:1,time:1000},function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }
                  }
              })
        })

    })
  </script>